<template>
  <public-footer>
    <header>
      <span class="iconfont icon-sousuoleimu"></span>
      <p>
        <input type="text" placeholder="输入商品名称搜索" />
        <span class="iconfont icon-sousuo"></span>
      </p>
      <span class="iconfont icon-sangedian"></span>
    </header>
    <div id="box">
      <div class="transverse">
        <ul>
          <li v-for="str in type" :key="str">{{ str }}</li>
        </ul>
      </div>
      <div id="banner">
        <van-swipe class="banner" :autoplay="3000" :height="210">
          <van-swipe-item v-for="(image, index) in bannerimg" :key="index">
            <img v-lazy="image" />
          </van-swipe-item>
        </van-swipe>
      </div>
      <div id="column">
        <ul>
          <li>
            <span class="iconfont icon-quanbushangpin"></span>
            <span>全部商品</span>
          </li>
          <li>
            <span class="iconfont icon-baokuan"></span>
            <span>爆款商品</span>
          </li>
          <li>
            <span class="iconfont icon-shangxin"></span>
            <span>新品上市</span>
          </li>
          <li>
            <span class="iconfont icon-dingdan"></span>
            <span>我的订单</span>
          </li>
        </ul>
      </div>
      <div id="bottom">
        <div
          class="list"
          v-for="itme in homeList"
          :key="itme.id"
        >
          <img :src="itme.banner[0].path" alt="" />
          <div>
            <span class="list_1">{{ itme.name }}</span>
            <p><span>开始</span>{{ itme.st | dateFormat("MM月DD日 hh时") }}</p>
            <p><span>结束</span>{{ itme.et | dateFormat("MM月DD日 hh时") }}</p>
            <span class="list_2">价格:￥ </span
            ><span class="list_3">{{ itme.price }}元</span>
            <br />
            <button @click="joinCart(itme)">加入购物车</button>
          </div>
        </div>
      </div>
      <p class="noTo">没有更多了</p>
    </div>
  </public-footer>
</template>


<script>
import { homeBannerApi, homeListApi, typesApi } from "../../apis/home";
import {cartAddApi} from '../../apis/types'
export default {
  data() {
    return {
      bannerimg: [],
      homeList: [],
      type: ["首页"],
    };
  },
  created() {
    //轮播图
    let banner = homeBannerApi();
    banner.then((data) => {
      this.bannerimg = data.data.rows.map((it) => {
        it.path = "http://www.shuiyue.info:12600" + it.path;
        return it.path;
      });
    });

    //首页展示商品
    let homeList = homeListApi();
    homeList.then((data) => {
      this.homeList = data.data.rows[7].product.map((it) => {
        it.banner[0].path = "http://www.shuiyue.info:12600" + it.banner[0].path;
        return it;
      });0
    });

    //分类列表
    let types = typesApi();
    types.then((data) => {
      data.data.forEach((el) => {
        this.type.push(el);
      });
    });
  },

  methods: {
    //加入购物车
    joinCart(obj){
      let cartAdd = cartAddApi({product: {...obj,count:1,checked:false}})
      cartAdd.then(data=>{
        if(data.code===200){
          this.$toast({
                message: `添加购物车成功`,
                position: "bottom",
              });
        }
      })
    },
  },
};
</script>

<style lang="less" scoped>
@import "../../style/reset.css";
header {
  height: 2.5rem;
  width: 100%;
  border-bottom: 1px solid rgb(179, 175, 175);
  display: flex;
  justify-content: space-evenly;
  > span {
    font-size: 1.5rem;
  }
  > p {
    height: 1.6rem;
    width: 13rem;
    padding-left: 0.5rem;
    margin-top: 0.45rem;
    line-height: 2.5rem;
    border-radius: 0.2rem;
    background-color: rgba(184, 187, 186, 0.5);
    position: relative;

    > input {
      height: 1.5rem;
      vertical-align: top;
      width: 10.5rem;
      border: none;
      background-color: transparent;
    }
    > span {
      vertical-align: top;
      font-size: 1rem;
      position: absolute;
      top: -10px;
      right: 8px;
    }
  }
}
#box {
  height: calc(100% - 2.5rem);
  overflow-x: hidden;
  > .transverse {
    height: 2rem;
    width: 100%;
    > ul {
      display: flex;
      overflow-y: hidden;
      > li {
        line-height: 2rem;
        font-size: 0.9rem;
        margin-left: 8px;
        margin-right: 8px;
        flex-shrink: 0;
        color: rgb(115, 119, 119);
        overflow-y: hidden;
      }
    }
  }
}
.banner {
  img {
    width: 100%;
    height: 210px;
  }
}
#column {
  width: 100%;
  height: 5rem;
  padding-top: 1rem;
  overflow: hidden;
  border-bottom: 1px solid rgb(138, 128, 128);
  ul {
    display: flex;
    li {
      width: 25vh;
      text-align: center;
      > span:nth-child(1) {
        display: block;
        font-size: 2rem;
        color: rgb(114, 122, 122);
      }
      > span:nth-child(2) {
        font-size: 0.6rem;
        display: block;
        margin-top: -5px;
      }
    }
  }
}
#bottom {
  padding-left: 5px;
  padding-right: 5px;
  background-color: rgb(255, 255, 255);
  .list:nth-child(2n-1) {
    padding-top: 0.5rem;
    width: 100%;
    height: 8rem;
    display: flex;
    border-bottom: 1px solid rgb(172, 167, 167);
    img {
      width: 45%;
      height: 80%;
      margin-right: 10px;
      margin-top: 0.5rem;
    }
    > div {
      margin-top: 0.5rem;
      font-size: 0.8rem;
      p:nth-child(2) {
        > span {
          font-size: 0.7rem;
          margin-right: 8px;
        }
      }
      p:nth-child(3) {
        > span {
          font-size: 0.7rem;
          margin-right: 8px;
        }
      }
      .list_2 {
        font-size: 0.7rem;
      }
      .list_3 {
        font-size: 0.8rem;
        color: rgb(255, 0, 0);
      }
      button {
        font-size: 0.7rem;
        width: 5rem;
        height: 1.5rem;
        float: right;
        margin-left: 4rem;
        border: none;
        margin-top: 0.5rem;
        color: rgb(255, 255, 255);
        background-color: rgb(255, 166, 0);
      }
    }
  }
  .list:nth-child(2n) {
    padding-top: 0.5rem;
    width: 100%;
    height: 8rem;
    border-bottom: 1px solid rgb(172, 167, 167);
    img {
      float: right;
      width: 45%;
      height: 80%;
      margin-right: 10px;
      margin-top: 0.5rem;
    }
    div {
      margin-left: 0.5rem;
      margin-top: 0.5rem;
      font-size: 0.8rem;
      p:nth-child(2) {
        > span {
          font-size: 0.7rem;
          margin-right: 8px;
        }
      }
      p:nth-child(3) {
        > span {
          font-size: 0.7rem;
          margin-right: 8px;
        }
      }
      .list_2 {
        font-size: 0.7rem;
      }
      .list_3 {
        font-size: 0.8rem;
        color: rgb(255, 0, 0);
      }
      button {
        font-size: 0.7rem;
        width: 5rem;
        height: 1.5rem;
        float: right;
        margin-right: 1rem;
        border: none;
        margin-top: 0.5rem;
        color: rgb(255, 255, 255);
        background-color: rgb(255, 166, 0);
      }
    }
  }
}
.noTo {
  width: 100%;
  height: 3rem;
  font-size: 1rem;
  text-align: center;
  line-height: 3rem;
}
</style>